#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2017, Fabian Greif
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

import os

def init(module):
    module.name = ":processing"
    module.description = """\
# Processing

Constructs to influence program flow execution, timing, synchronization
and delegation.
"""

def prepare(module, options):
    return True

def build(env):
    env.outbasepath = "modm/src/modm/processing"
    env.copy("task.hpp")

    if env.has_module(":architecture:fiber") and not env.has_module(":processing:fiber"):
        env.outbasepath = "modm/src/modm/processing/"
        env.substitutions = {"with_task": False}
        env.copy("fiber/no_yield.hpp")
        env.template("fiber.hpp.in")

    env.outbasepath = "modm/src/modm"
    headers = env.generated_local_files(filterfunc=lambda path: ".hpp" in path and path.count(os.path.sep) == 1)
    env.template("processing.hpp.in", substitutions={"headers": sorted(headers)})
